﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
    xmlns:ee="http://schemas.microsoft.com/expression/2010/effects"
   xmlns:views="clr-namespace:LayoutPlanning.Views"
    xmlns:model="clr-namespace:LayoutPlanning.Model"
    xmlns:helpers="clr-namespace:LayoutPlanning.Helpers"
    xmlns:pt="http://propertytools.org/wpf"
    xmlns:controls="clr-namespace:LayoutPlanning.Controls"
    xmlns:eventToCommand="clr-namespace:Mvvm.UI.Behaviors.EventToCommand;assembly=Mvvm"
    xmlns:interactivity="clr-namespace:Mvvm.UI.Interactivity;assembly=Mvvm"
    x:Class="LayoutPlanning.Views.MainView"
    mc:Ignorable="d"
    Title="Layout Tool 3d Silver" Height="1014.87" Width="1693" DataContext="{DynamicResource Locator}"
    Icon="/LayoutPlanning;component/Images/LayoutIcon.ico" Background="GhostWhite" Style="{StaticResource ApplicationFonts}"  >
    <Window.Resources>
        <ControlTemplate x:Key="ButtonControlTemplate1" TargetType="{x:Type Button}">
            <ControlTemplate.Resources>
                <Storyboard x:Key="Storyboard1">
                    <ColorAnimationUsingKeyFrames
                        Storyboard.TargetProperty="(UIElement.Effect).(ee:ColorToneEffect.DarkColor)"
                        Storyboard.TargetName="contentPresenter">
                        <EasingColorKeyFrame KeyTime="0" Value="#FFFFE800" />
                    </ColorAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames
                        Storyboard.TargetProperty="(UIElement.Effect).(ee:ColorToneEffect.Desaturation)"
                        Storyboard.TargetName="contentPresenter">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0.9" />
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames
                        Storyboard.TargetProperty="(UIElement.Effect).(ee:ColorToneEffect.ToneAmount)"
                        Storyboard.TargetName="contentPresenter">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0.9" />
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </ControlTemplate.Resources>
            <ContentPresenter x:Name="contentPresenter">
                <ContentPresenter.Effect>
                    <ee:ColorToneEffect Desaturation="0" ToneAmount="0" />
                </ContentPresenter.Effect>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualStateGroup.Transitions>
                            <VisualTransition From="MouseOver" GeneratedDuration="0" To="Normal" />
                        </VisualStateGroup.Transitions>
                        <VisualState x:Name="Normal" />
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <ColorAnimationUsingKeyFrames
                                    Storyboard.TargetProperty="(UIElement.Effect).(ee:ColorToneEffect.DarkColor)"
                                    Storyboard.TargetName="contentPresenter">
                                    <EasingColorKeyFrame KeyTime="0" Value="#FFFDE600" />
                                </ColorAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames
                                    Storyboard.TargetProperty="(UIElement.Effect).(ee:ColorToneEffect.Desaturation)"
                                    Storyboard.TargetName="contentPresenter">
                                    <EasingDoubleKeyFrame KeyTime="0" Value="0.9" />
                                </DoubleAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames
                                    Storyboard.TargetProperty="(UIElement.Effect).(ee:ColorToneEffect.ToneAmount)"
                                    Storyboard.TargetName="contentPresenter">
                                    <EasingDoubleKeyFrame KeyTime="0" Value="0.9" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Pressed" />
                        <VisualState x:Name="Disabled" />
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
            </ContentPresenter>
        </ControlTemplate>
        <ControlTemplate x:Key="ListBoxItemControl" TargetType="{x:Type ListBoxItem}">

            <Grid  Name="TGrid" Background="{DynamicResource ButtonNormalBackground}">

                <ContentPresenter Height="40" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="true">
                    <Setter TargetName="TGrid" Property="Opacity"
                    Value="0.50"/>
                </Trigger>
                <Trigger Property="IsSelected" Value="true">
                    <Setter TargetName="TGrid" Property="OpacityMask" Value="LightSkyBlue"/>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="TGrid" Property="Opacity"
                    Value="0.3"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

    </Window.Resources>
    <DockPanel DataContext="{Binding Main}" Margin="0" d:LayoutOverrides="HorizontalAlignment">
        <Border Padding="5" DockPanel.Dock="Left" BorderBrush="Black" BorderThickness="1" Margin="5" Width="232">
            <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="0">
                <StackPanel Margin="0">
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Height="22" Margin="0,0,-1,0" TextWrapping="Wrap" Text="Stations"
                                       RenderTransformOrigin="0.528,-0.364" FontWeight="Bold" />
                            <Expander IsExpanded="True" Name="StationExpander" HorizontalAlignment="Right" />
                        </StackPanel>
                        <ListBox
                            Visibility="{Binding IsExpanded, ElementName=StationExpander, Converter={StaticResource BoolToVisability} }"
                            BorderBrush="Black" Height="333" ItemsSource="{Binding  Stations}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel MouseDown="UIElement_OnMouseDown">
                                        <TextBlock Text="{Binding Name}" />
                                        <Viewbox Stretch="Uniform"  MaxWidth="200" MaxHeight="120">
                                            <StackPanel MouseDown="UIElement_OnMouseDown"  Background="{Binding NormalColor}">
                                                <ContentControl  Width="{Binding SizeX}" Height="{Binding SizeY}" Content="{Binding Control}" />
                                            </StackPanel>
                                        </Viewbox>
                                        <Button Content="{Binding SyncedText}" Command="{Binding SaveUpdate}"></Button>
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Height="22" Margin="0,0,-1,0" TextWrapping="Wrap" Text="New Tasks"
                                   RenderTransformOrigin="0.528,-0.364" FontWeight="Bold" />
                        <Expander IsExpanded="True" Name="TaskExpander" HorizontalAlignment="Right" />
                    </StackPanel>
                    <Border
                        Visibility="{Binding IsExpanded, ElementName=TaskExpander, Converter={StaticResource BoolToVisability}}"
                        BorderThickness="1" BorderBrush="Black">

                        <ListBox SelectedValue="{Binding SelectedNewTask}" >
                            <ListBox.Items>
                                <ListBoxItem Name="Walk" HorizontalAlignment="Stretch" Template="{DynamicResource ListBoxItemControl}">

                                    <!--<Button Height="34" VerticalAlignment="Top"
                                        Template="{DynamicResource ButtonControlTemplate1}" Width="167">-->
                                    <Grid HorizontalAlignment="Stretch"   >
                                        <ed:LineArrow BendAmount="0" EndArrow="OpenArrow" Margin="2,0,35,8"
                                                      StartArrow="NoArrow" Stroke="#FF3AC38B"
                                                      RenderTransformOrigin="0.717,0.456" StrokeThickness="3" />
                                        <Label Content="Walk" Margin="5,8,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" RenderTransformOrigin="-0.083,0.654" />
                                    </Grid>

                                </ListBoxItem>
                                <ListBoxItem Name="Work" Template="{DynamicResource ListBoxItemControl}">
                                    <!--<Button Height="45" VerticalAlignment="Top"
                                        Template="{DynamicResource ButtonControlTemplate1}">-->
                                    <Grid Margin="0"  >
                                        <Label Content="Work" HorizontalAlignment="Left"  VerticalAlignment="Top" Margin="5,8,0,0"   />

                                        <Grid Margin="153,3,0,0" Height="27" VerticalAlignment="Top" HorizontalAlignment="Left" Width="29">
                                            <ed:Arc ArcThickness="20" ArcThicknessUnit="Pixel" EndAngle="360"
                                                    Stretch="None" Stroke="#FFF50D17" StrokeThickness="3" StartAngle="0"
                                                    HorizontalAlignment="Left" Width="23"  Margin="2,4,0,0"
                                                    RenderTransformOrigin="0.348,0.233" Height="22" VerticalAlignment="Top" />
                                            <ed:LineArrow BendAmount="0" EndArrow="OpenArrow"
                                                          Height="9" Margin="14,7,0,0" StartArrow="NoArrow"
                                                          Stroke="#FFF50D17" StrokeThickness="3" VerticalAlignment="Top" ArrowSize="1" HorizontalAlignment="Left" Width="0" />
                                            <ed:LineArrow BendAmount="0" EndArrow="OpenArrow" HorizontalAlignment="Left"
                                                          Margin="13,17,0,0" StartArrow="NoArrow"
                                                          Stroke="#FFF50D17" StrokeThickness="1" Width="4"
                                                          ArrowSize="1" RenderTransformOrigin="0.5,0.5" Height="2" VerticalAlignment="Top">
                                                <ed:LineArrow.RenderTransform>
                                                    <TransformGroup>
                                                        <ScaleTransform ScaleY="-1" ScaleX="-1" />
                                                        <SkewTransform />
                                                        <RotateTransform Angle="-130.889" />
                                                        <TranslateTransform />
                                                    </TransformGroup>
                                                </ed:LineArrow.RenderTransform>
                                            </ed:LineArrow>
                                        </Grid>
                                    </Grid>

                                </ListBoxItem>
                                <ListBoxItem Name="Carry" Template="{DynamicResource ListBoxItemControl}">
                                    <!--<Button x:Name="grid_Copy1" Height="145" VerticalAlignment="Top"
                                    Template="{DynamicResource ButtonControlTemplate1}">-->
                                    <Grid Margin="0">
                                        <ed:LineArrow BendAmount="0" EndArrow="OpenArrow" 
                                                  StartArrow="NoArrow" Stroke="#FF0C00FF"
                                                  RenderTransformOrigin="0.717,0.456" StrokeThickness="3" HorizontalAlignment="Left" Width="176" Height="30" VerticalAlignment="Top" Margin="0,0,-7,0" />
                                        <ed:Arc ArcThickness="20" ArcThicknessUnit="Pixel" EndAngle="360"
                                                    Stretch="None" Stroke="Black" StrokeThickness="12" StartAngle="0"
                                                    HorizontalAlignment="Left" Width="23"  Margin="70,2,0,0"
                                                    RenderTransformOrigin="0.348,0.233" Height="22" VerticalAlignment="Top" />
                                        <Label Content="Carry" Margin="5,8,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
                                    </Grid>

                                </ListBoxItem>
                            </ListBox.Items>
                        </ListBox>
                    </Border>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Height="22" Margin="0,0,-1,0" TextWrapping="Wrap"
                                   Text="Work Order" RenderTransformOrigin="0.528,-0.364" FontWeight="Bold" />
                        <Expander IsExpanded="True" Name="WorkOrderExpander" HorizontalAlignment="Right" />
                    </StackPanel>
                    <Border
                        Visibility="{Binding IsExpanded, Converter={StaticResource BoolToVisability}, ElementName=WorkOrderExpander}"
                        BorderThickness="1" BorderBrush="Black">
                        <StackPanel MinHeight="52">
                            <views:ConfigWorkTaskView DataContext="{Binding Main.NewTask, Source={StaticResource Locator}}" Visibility="{Binding TargetNullValue={x:Static Visibility.Collapsed},  Converter={StaticResource NullToVisibilityConverterInverted}}"/>
                            <Button Command="{Binding AddTask}" IsEnabled="{Binding SelectedNewTask, Converter={StaticResource NullToBool}}" Content="Add Task"/>
                        </StackPanel>
                    </Border>


                    <StackPanel Orientation="Horizontal">
                        <TextBlock Height="22" Margin="0,0,0,0" TextWrapping="Wrap" Text="Current Order"
                                   RenderTransformOrigin="0.528,-0.364" FontWeight="Bold" />
                        <Expander IsExpanded="True" Name="TaskListExpander" HorizontalAlignment="Right" />
                    </StackPanel>
                    <Border 
                        Visibility="{Binding IsExpanded, ElementName=TaskListExpander, Converter={StaticResource BoolToVisability}}"
                        BorderThickness="1" BorderBrush="Black">
                        <StackPanel    >
                            <ListBox Name="worktasklistbox"  SelectionMode="Single"  MouseRightButtonUp="worktasklistboxMouseClear" Background="Transparent" MinHeight="100" ItemsSource="{Binding CurrentWorkOrder.Worktasks}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <TextBlock Text="{Binding TaskName}" FontSize="12" />
                                            <views:ConfigWorkTaskView  DataContext="{Binding }" Visibility="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}, Converter={StaticResource BoolToVisability}}" />
                                            <Button Content="Delete" Command="{Binding Main.DeleteTask, Source={StaticResource Locator}}" CommandParameter="{Binding }" />
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </Border>
                </StackPanel>
            </ScrollViewer>
        </Border>
        <Border BorderBrush="Black" Margin="5" BorderThickness="1" Height="60" VerticalAlignment="Top"
                HorizontalAlignment="Stretch" DockPanel.Dock="Top">
            <StackPanel Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal">
                <Border BorderBrush="Black" BorderThickness="1"  VerticalAlignment="Top"
                        HorizontalAlignment="Stretch" DockPanel.Dock="Top">
                    <StackPanel Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
                                Orientation="Horizontal">
                        <Button  Command="{Binding SaveAreaCommand }" Content="Save Project and Layout" HorizontalAlignment="Left" VerticalAlignment="Top" />
                    </StackPanel>
                </Border>
                <Border Margin="5,0,0,0" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Top"
                        HorizontalAlignment="Stretch" DockPanel.Dock="Top">
                    <StackPanel Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
                                Orientation="Horizontal">
                        <Button Content="Load Station" Command="{Binding LoadStationCommand}"
                                VerticalAlignment="Center" Margin="0,0" HorizontalAlignment="Left" />
                    </StackPanel>
                </Border>
                <Border Margin="5,0,0,0" BorderBrush="Black" BorderThickness="1"  VerticalAlignment="Top"
                        HorizontalAlignment="Stretch" DockPanel.Dock="Top">
                    <StackPanel Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
                                Orientation="Horizontal">
                        <Button Command="{Binding DrawObsticle}" VerticalAlignment="Center" Margin="0,0"
                                HorizontalAlignment="Left" Content="Draw Obstacle" />
                        <Button Command="{Binding DrawStorageSpace}" VerticalAlignment="Center" Margin="5,0,0,0"
                                HorizontalAlignment="Left" Content="Draw Storage " />

                    </StackPanel>
                </Border>
                <Border Margin="5,0,0,0" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Top"
                        HorizontalAlignment="Stretch" DockPanel.Dock="Top">
                    <StackPanel Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
                                Orientation="Horizontal">
                        <Button Command="{Binding SendToImma}" Content="Send to IMMA" VerticalAlignment="Center" HorizontalAlignment="Left"
                                Margin="0,0,0,0" />
                        <Button VerticalAlignment="Center" Margin="5,0,0,0" HorizontalAlignment="Left"
                                Content="Load from IMMA" Command="{Binding LoadImma}" />

                    </StackPanel>
                </Border>
                <Border Margin="5,0,0,0" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Top"
                    HorizontalAlignment="Stretch">
                    <StackPanel Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
                        Orientation="Horizontal">
                        <Button  Command="{Binding OptimizePositionsOfMachines}" Content="{Binding OptimizationButtonText}" VerticalAlignment="Center" HorizontalAlignment="Left"
                            Margin="0,0,5,0" />

                        <TextBlock Text="Optimization Sound Sensitiveness:"></TextBlock>
                        <pt:SpinControl Value="{Binding SoundSensitivness}" Margin="5,0" HorizontalAlignment="Left" SmallChange="1000" Maximum="100000000000000" 
                	Width="100" Height="21" VerticalAlignment="Top"    >

                            <TextBox Text="{Binding SoundSensitivness, StringFormat=0}" BorderThickness="0"/>
                        </pt:SpinControl>

                    </StackPanel>
                </Border>
                <Border Margin="5,0,0,0" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Top"
                        HorizontalAlignment="Stretch" DockPanel.Dock="Top">
                    <StackPanel Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
                                Orientation="Horizontal">
                        <Button Command="{Binding PrintView}" CommandParameter="{Binding ElementName=PrintView}" Content="Print Current View" VerticalAlignment="Center" HorizontalAlignment="Left"
                                Margin="0,0,0,0" />

                    </StackPanel>
                </Border>
            </StackPanel>
        </Border>
        <Border  Visibility="{Binding SelectedGraficalObject, Converter={StaticResource NullToVisibilityConverterInverted}}" BorderBrush="Black" Margin="5" BorderThickness="1" Height="137" VerticalAlignment="Top"
                HorizontalAlignment="Stretch" DockPanel.Dock="Top">
            <ScrollViewer CanContentScroll="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                <Grid DataContext="{Binding SelectedGraficalObject}" Margin="5" VerticalAlignment="Stretch"
                  HorizontalAlignment="Stretch">

                    <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="195,63,0,0" TextWrapping="Wrap" Text="Relative Origo X"
                           Height="20" VerticalAlignment="Top" RenderTransformOrigin="0.257,0.717"  >

                    </TextBlock>
                    <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="195,88,0,0" TextWrapping="Wrap" Text="Relative Origo Y"
                           Height="20" VerticalAlignment="Top" RenderTransformOrigin="0.257,0.717" />
                    <pt:SpinControl Value="{Binding Origo.X}" Maximum="100000000" HorizontalAlignment="Left" Margin="297,63,0,0"
                                   Width="65" VerticalAlignment="Top" Height="20" >
                        <TextBox Text="{Binding Origo.X, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                    </pt:SpinControl>
                    <pt:SpinControl Value="{Binding Origo.Y}" Maximum="100000000" HorizontalAlignment="Left" Margin="297,88,0,0"
                                   Width="65" Height="21" VerticalAlignment="Top"    >
                        <TextBox Text="{Binding Origo.Y, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                    </pt:SpinControl>

                    <TextBox TextWrapping="Wrap" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"
                         HorizontalAlignment="Left" Height="22" VerticalAlignment="Top" Width="240" Margin="285,0,0,0" />
                    <TextBox TextWrapping="Wrap" Text="{Binding PointCloudFile, UpdateSourceTrigger=PropertyChanged}"
                         HorizontalAlignment="Left" Height="22" VerticalAlignment="Top" Width="240" Margin="285,32,0,0" />
                    <pt:SpinControl  Value="{Binding Position.X}" HorizontalAlignment="Left" Maximum="100000000" Margin="51,32,0,0"
                                   Width="138" VerticalAlignment="Top" Height="20"  >
                        <TextBox Text="{Binding Position.X, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                    </pt:SpinControl>
                    <pt:SpinControl Value="{Binding Position.Y}" HorizontalAlignment="Left" Maximum="100000000" Margin="51,57,0,0"
                                   Width="138" Height="21" VerticalAlignment="Top"  >
                        <TextBox Text="{Binding Position.Y, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                    </pt:SpinControl>
                    <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="40,58,0,0" TextWrapping="Wrap" Text="Y"
                           Height="20" VerticalAlignment="Top" />
                    <TextBlock HorizontalAlignment="Left" Margin="40,32,0,0" TextWrapping="Wrap" Text="X" Height="20"
                           VerticalAlignment="Top" />
                    <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="248,2,0,0" TextWrapping="Wrap" Text="Name"
                           Height="20" VerticalAlignment="Top" RenderTransformOrigin="0.257,0.717" />
                    <pt:SpinControl Value="{Binding Angle}" HorizontalAlignment="Left" Margin="51,7,0,0" Width="138"
                                   VerticalAlignment="Top" Height="20" Maximum="360" >
                        <TextBox Text="{Binding Angle, StringFormat=0.#}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                    </pt:SpinControl>
                    <TextBlock HorizontalAlignment="Left" Margin="1,7,0,0" TextWrapping="Wrap" Text="Rotation" Height="20"
                           VerticalAlignment="Top" />
                    <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="201,34,0,0" TextWrapping="Wrap" Text="PointCloudFile"
                	Height="20" VerticalAlignment="Top" RenderTransformOrigin="0.257,0.717" />
                    <Button Command="{Binding BrowsePointCloudFile}" Content="Browse" HorizontalAlignment="Left" Margin="530,32,0,0" VerticalAlignment="Top" Width="75"/>
                    <TextBlock Text="Color: " Margin="593,5,0,0" HorizontalAlignment="Left" Width="35" Height="22" VerticalAlignment="Top"></TextBlock>
                    <pt:ColorPicker SelectedColor="{Binding NormalColorString}" Margin="633,3,0,0" HorizontalAlignment="Left"   VerticalAlignment="Top"></pt:ColorPicker>
                    <!-- Station Specifics -->
                    <Grid DataContext="{Binding  Main.SelectedStation,Source={StaticResource Locator}}"  Visibility="{Binding Converter={StaticResource NullToVisibilityConverterInverted}}" Margin="12,3,10,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="867"/>
                            <ColumnDefinition Width="486*"/>

                        </Grid.ColumnDefinitions>

                        <ComboBox SelectedValue="{Binding Loudness}"  ItemsSource="{Binding Source={helpers:Enumeration {x:Type model:Loudness}}}" SelectedValuePath="Value" DisplayMemberPath="Value" HorizontalAlignment="Left" Margin="39,0,0,20" Width="138" VerticalAlignment="Bottom" Height="20" SelectedIndex="0" />
                        <TextBlock HorizontalAlignment="Left" Margin="0,85,0,0" TextWrapping="Wrap" Text="Sound"
                		VerticalAlignment="Top"  />
                        <CheckBox IsChecked="{Binding SoundSensitiv}" Content="Sound Sensitive" HorizontalAlignment="Left"
                		Margin="28,107,0,0" VerticalAlignment="Top" />
                        <StackPanel Orientation="Vertical" HorizontalAlignment="Left"  VerticalAlignment="Top" Grid.Column="1"  Width="400" >

                            <Button Command="{Binding AddWorkPosition}" Content="Add Work Position" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                            <ListBox SelectionMode="Single" MouseLeftButtonUp="UIElement_OnMouseLeftButtonUp" ItemsSource="{Binding WorkPositions}" SelectedValue="{Binding SelectedWorkGripPosition}"  HorizontalAlignment="Left" MinHeight ="22"  MaxHeight="100" Margin="0" VerticalAlignment="Top" MinWidth="400">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                            <TextBlock Margin="3,0" Text="X:"/>
                                            <pt:SpinControl  Value="{Binding Position.X}" Minimum="0"  SmallChange="0.1"   >
                                                <TextBox Text="{Binding Position.X, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                                            </pt:SpinControl>
                                            <TextBlock Margin="3,0" Text="Y:"/>
                                            <pt:SpinControl  Value="{Binding Position.Y}" Minimum="0"  SmallChange="0.1"   >
                                                <TextBox Text="{Binding Position.Y, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                                            </pt:SpinControl>
                                            <TextBlock Margin="3,0" Text="Angel:"/>
                                            <pt:SpinControl  Value="{Binding Angle}" Minimum="0"  SmallChange="0.1"   >
                                                <TextBox Text="{Binding Angle, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                                            </pt:SpinControl>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>



                            <Button Command="{Binding AddGripPosition}" Content="Add Grip Position" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                            <ListBox SelectionMode="Single" MouseLeftButtonUp="UIElement_OnMouseLeftButtonUp" ItemsSource="{Binding GripPositions}" SelectedValue="{Binding SelectedWorkGripPosition}"  HorizontalAlignment="Left" MinHeight="22" MaxHeight="100" VerticalAlignment="Stretch" MinWidth="400">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                            <TextBlock Text=" X:"/>
                                            <ComboBox SelectedValue="{Binding GripType}" DisplayMemberPath="Description"  ItemsSource="{Binding  Source={helpers:Enumeration {x:Type model:GripTypes}}}" />
                                            <TextBlock Text=" X:"/>
                                            <pt:SpinControl  Value="{Binding Position.X}" Minimum="0"  SmallChange="0.1"   >
                                                <TextBox Text="{Binding Position.X, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                                            </pt:SpinControl>
                                            <TextBlock Text="Y:"/>
                                            <pt:SpinControl  Value="{Binding Position.Y}" Minimum="0"  SmallChange="0.1"   >
                                                <TextBox Text="{Binding Position.Y, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                                            </pt:SpinControl>
                                            <TextBlock Text="Z:"/>
                                            <pt:SpinControl  Value="{Binding Position.Z}" Minimum="0"  SmallChange="0.1"   >
                                                <TextBox Text="{Binding Position.Z, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                                            </pt:SpinControl>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </Grid>
                    <!-- Storage Specifics -->
                    <Grid DataContext="{Binding  Main.SelectedStorage,Source={StaticResource Locator}}" Visibility="{Binding Converter={StaticResource NullToVisibilityConverterInverted}}" Margin="91,4,-69,-1">
                        <ListBox SelectionMode="Single" MouseLeftButtonUp="UIElement_OnMouseLeftButtonUp" ItemsSource="{Binding Products}" SelectedValue="{Binding SelectedProduct}"  HorizontalAlignment="Left" MinHeight="83" Margin="788,29,0,0" VerticalAlignment="Top" MinWidth="240">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBox MinWidth="60" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                        <TextBlock Margin="5,0"  Text=" Weight:"/>
                                        <pt:SpinControl  Value="{Binding Weight}" Minimum="0" Maximum="100000000"  SmallChange="0.1"   >
                                            <TextBox Text="{Binding Weight, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                                        </pt:SpinControl>
                                        <TextBlock Margin="5,0" Text="Grafics:"/>
                                        <TextBox MinWidth="40" Text="{Binding GraficFile}"/>
                                        <Button Margin="5,0" Content="Browse" Command="{Binding ChooseFiles}" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>

                        <Button Command="{Binding AddProduct}" Content="Add Product" HorizontalAlignment="Left" Margin="788,0,0,0" VerticalAlignment="Top"/>

                    </Grid>
                    <Border Margin="394,59,0,0"  VerticalAlignment="Top" HorizontalAlignment="Left" >
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="Grafical Form"></TextBlock>
                            <RadioButton GroupName="Form" IsChecked="{Binding ControlType, Mode=OneWay, Converter={StaticResource ControlTypeChecked}, ConverterParameter=Square }" Content="Square" HorizontalAlignment="Left"  VerticalAlignment="Top">
                                <interactivity:Interaction.Behaviors>
                                    <eventToCommand:EventToCommand  EventName="Checked" Command="{Binding ChangeShape}" CommandParameter="Square" ></eventToCommand:EventToCommand>
                                </interactivity:Interaction.Behaviors>
                            </RadioButton>
                            <RadioButton GroupName="Form" Content="Circle" IsChecked="{Binding ControlType, Mode=OneWay, Converter={StaticResource ControlTypeChecked}, ConverterParameter=Circle }" HorizontalAlignment="Left"  VerticalAlignment="Top">
                                <interactivity:Interaction.Behaviors>
                                    <eventToCommand:EventToCommand  EventName="Checked" Command="{Binding ChangeShape}" CommandParameter="Circle" ></eventToCommand:EventToCommand>
                                </interactivity:Interaction.Behaviors>
                            </RadioButton>
                            <RadioButton GroupName="Form" Content="Custom" HorizontalAlignment="Left" IsChecked="{Binding ControlType, Mode=OneWay, Converter={StaticResource ControlTypeChecked}, ConverterParameter=Custom }"   VerticalAlignment="Top">
                                <interactivity:Interaction.Behaviors>
                                    <eventToCommand:EventToCommand  EventName="Checked" Command="{Binding ChangeShape}" CommandParameter="Custom" ></eventToCommand:EventToCommand>
                                </interactivity:Interaction.Behaviors>
                            </RadioButton>
                        </StackPanel>
                    </Border>
                    <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="494,70,0,0" TextWrapping="Wrap" Text="Size X"
                	Height="20" VerticalAlignment="Top" RenderTransformOrigin="0.257,0.717" />
                    <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="494,95,0,0" TextWrapping="Wrap" Text="Size Y"
                	Height="20" VerticalAlignment="Top" RenderTransformOrigin="0.257,0.717" />
                    <pt:SpinControl Value="{Binding SizeX}" Maximum="100000000" HorizontalAlignment="Left" Margin="530,68,0,0"
                	Width="65" VerticalAlignment="Top" Height="20" >
                        <TextBox Text="{Binding SizeX, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                    </pt:SpinControl>
                    <pt:SpinControl Value="{Binding SizeY}" HorizontalAlignment="Left" Maximum="100000000" Margin="530,93,0,0"
                	Width="65" Height="21" VerticalAlignment="Top"    >
                        <TextBox Text="{Binding SizeY, StringFormat=0.##}" BorderThickness="0" HorizontalContentAlignment="Right"/>
                    </pt:SpinControl>
                    <ListBox ItemsSource="{Binding SpecialRelations}" x:Name="listBox" HorizontalAlignment="Left" Height="63" Margin="633,57,0,0" VerticalAlignment="Top" Width="238">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <ComboBox SelectedItem="{Binding RelationTo}" DisplayMemberPath="Name" ItemsSource="{Binding Main.DeployedStations,Source={StaticResource Locator}}"></ComboBox>

                                    <ComboBox SelectedValue="{Binding TypeOfRelation}" SelectedValuePath="Value"    ItemsSource="{Binding Source={helpers:Enumeration {x:Type model:RelationType}}}" DisplayMemberPath="Description"  />
                                    <Button Content="Delete" Command="{Binding Delete}" CommandParameter="{Binding Main.SelectedGraficalObject ,Source={StaticResource Locator}}"></Button>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <Button Command="{Binding AddSpecialRelation}" Content="Add Special Relation" HorizontalAlignment="Left" Margin="633,32,0,0"  VerticalAlignment="Top"/>



                </Grid>

            </ScrollViewer>

        </Border>
        <Border BorderBrush="Black" Margin="5" Padding="5" BorderThickness="1" Height="30" VerticalAlignment="Bottom"
                HorizontalAlignment="Stretch" DockPanel.Dock="Bottom">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                <CheckBox Content="Visualize loud machines" IsChecked="{Binding ShowSound}" />
                <CheckBox Content="Visualize workorders" Margin="5,0" IsChecked="{Binding ShowSpagetti}"/>
                <CheckBox Content="Visualize negative impacts" IsChecked="{Binding ShowSound}"/>
                <TextBlock Text="  Zoom" />
                <Slider Margin="5,0" Minimum="0.001" Maximum="3" Value="{Binding Zoom, Converter={StaticResource LogNormal}}" Width="200" />
                <controls:SpinLogControl Value="{Binding Zoom}" Style="{StaticResource SpinLogStyle}"  >
                    <TextBox Text="{Binding Zoom, StringFormat=0.###,UpdateSourceTrigger=Default}"/>
                </controls:SpinLogControl>
            </StackPanel>
        </Border>
        <DockPanel MaxWidth="200" Margin="5" DockPanel.Dock="Right" >
            <Border DockPanel.Dock="Top"  Visibility="{Binding Results, Converter={StaticResource NullToVisibilityConverterInverted}, FallbackValue=Null}"  DataContext="{Binding Results}"  BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <StackPanel>
                    <TextBlock Text="Results" FontSize="20" />
                    <TextBlock Text="Operation Time:" />
                    <TextBlock Text="{Binding OpTime}" />
                </StackPanel>
            </Border>
            <Border DockPanel.Dock="Top"  Margin="0,5,0,5" DataContext="{Binding Layouts ,Source={StaticResource Locator}}"  BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <views:LoadLayout Height="480"></views:LoadLayout>
            </Border>
            <Border DockPanel.Dock="Top"  DataContext="{Binding Layouts ,Source={StaticResource Locator}}"  BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <DockPanel>
                    <Button Content="Draw Project Area" DockPanel.Dock="Top" Command="{Binding Main.DrawProjectArea, Source={StaticResource Locator}}" ></Button>
                    <ListBox Width="200" DockPanel.Dock="Top" SelectedItem="{Binding SelectedProject}" ItemsSource="{Binding ProjectsInLayout}" HorizontalAlignment="Stretch">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Border BorderThickness="1">
                                    <DockPanel  >
                                        <TextBox DockPanel.Dock="Top"  Text="{Binding Name}"></TextBox>
                                        <Button HorizontalAlignment="Left"  DockPanel.Dock="Top"  Content="Delete" Command="{Binding Layouts.DeleteProject, Source={StaticResource Locator}}" CommandParameter="{Binding Project}"></Button>
                                        <StackPanel Orientation="Horizontal">
                                        <pt:SpinControl DockPanel.Dock="Bottom" Value="{Binding  PosX}" Maximum="1000000" SmallChange="100">
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="Pos X: ">
                                                </TextBlock>
                                                <TextBox Text="{Binding  PosX}"></TextBox>
                                            </StackPanel>
                                        </pt:SpinControl>
                                        <pt:SpinControl DockPanel.Dock="Bottom" Value="{Binding  PosY}"  Maximum="1000000" SmallChange="100">
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="Pos Y: ">
                                                </TextBlock>
                                                <TextBox Text="{Binding PosY}"></TextBox>
                                            </StackPanel>
                                        </pt:SpinControl>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                        <pt:SpinControl DockPanel.Dock="Bottom"  Value="{Binding SizeX}" Maximum="{Binding Main.Layout.Width, Source={StaticResource Locator}}" SmallChange="100">
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="Size X: ">
                                                </TextBlock>
                                                <TextBox Text="{Binding SizeX}" ></TextBox>
                                            </StackPanel>
                                        </pt:SpinControl>

                                        <pt:SpinControl DockPanel.Dock="Bottom" Value="{Binding SizeY}" Maximum="{Binding Main.Layout.Height, Source={StaticResource Locator}}" SmallChange="100" >
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="Size Y: ">
                                                </TextBlock>
                                                <TextBox Text="{Binding SizeY}"></TextBox>
                                            </StackPanel>
                                        </pt:SpinControl>
                                        </StackPanel>
                                    </DockPanel>
                                </Border>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </DockPanel>
            </Border>
        </DockPanel>
        <Grid x:Name="PrintView" DockPanel.Dock="Right" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,5,5,5">
            <Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Grid  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <Grid >
                        <views:WorkStationView DataContext="{Binding SelectedStation}" Visibility="{Binding SelectedWorkGripPosition, Converter={StaticResource NullToVisibilityConverterInverted}, FallbackValue={x:Static Visibility.Collapsed}}" Height="Auto" Width="Auto" Margin="0,26,0,0"
                                  />
                    </Grid>
                    <Grid ClipToBounds="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  DataContext="{Binding SelectedStation}" Visibility="{Binding SelectedWorkGripPosition, Converter={StaticResource NullToVisibilityConverter}}">


                        <views:LayoutView   DataContext="{Binding Main, Source={StaticResource Locator}}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Height="Auto" Width="Auto" 
                                      Cursor="{Binding DrawNewSquare, Converter={StaticResource BoolToCursor}}"
                                      ForceCursor="True" />
                    </Grid>
                </Grid>
            </Border>
            <TextBlock Height="18" Margin="10,10,0,0" TextWrapping="Wrap" RenderTransformOrigin="0.528,-0.364"
                       HorizontalAlignment="Left" VerticalAlignment="Top" Width="109"
                       Text="{Binding Layout.LayoutName}" FontWeight="Bold" />


        </Grid>


    </DockPanel>
</Window>















